package com.labmi.experiment;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToMany;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;


@MappedSuperclass
public abstract class Item implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2127746271099047705L;
	
	@Id
	@GeneratedValue
	private long id;
	
	/**
	 * Identify an article type. This code is equals for articles that differ only
	 * for their size or color.
	 */
	private String code; 
	
	private int price;
	
	private Amount amount;
	private String name;
	private String description;
	private String detailImage;
	
	
	@OneToMany(cascade=CascadeType.ALL)
	private List<ItemStock> itemStockList;
	
	public Item (String name, String description, int price, String detailImage) {
	
		this.name = name;
		this.description = description;
		this.price = price;
		this.detailImage = detailImage;
	}
	

	public Item() {
		// TODO Auto-generated constructor stub
	}
	
	
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	public long getId() {
		return id;
	}
	public void setDetailImage(String image) {
		this.detailImage = image;
	}
	public String getDetailImage() {
		return detailImage;
	}
	public void setAmount(Amount amount) {
		this.amount = amount;
	}
	public Amount getAmount() {
		return amount;
	}




	public int getItemsInStock() {
		return itemStockList.size();
	}


	public void setCode(String code) {
		this.code = code;
	}


	public String getCode() {
		return code;
	}

	
	public void addItemStock(ItemStock itemStock) {
		if(itemStock != null)
		{
			if(itemStockList == null)
				itemStockList = new ArrayList<ItemStock>();
			
			this.itemStockList.add(itemStock);
			
			if(itemStock.getItem() != this )			
				itemStock.setItem(this);
		}
			
	}

	public void setItemStockList(List<ItemStock> itemStockList) {
		this.itemStockList = itemStockList;
	}

	public List<ItemStock> getItemStockList() {
		return itemStockList;
	}
	
	
	
}
